MODULE_NAME='IR TV'
(
	Dev dvTV,
	Dev vdvTV
)
(***********************************************************)
(***********************************************************)
(*  FILE_LAST_MODIFIED_ON: 04/04/2006  AT: 11:33:16        *)
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)
(*
    $History: $
*)    
(***********************************************************)
(*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_DEVICE

(***********************************************************)
(*               CONSTANT DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_CONSTANT
cnTV_On = 1
cnTV_Off = 2
cnTV_Input1 = 3
cnTV_Input2 = 4
cnTV_Input3 = 5
cnTV_Input4 = 6
cnTV_Input5 = 7
cnTV_Input6 = 8

cnIR_On = 27
cnIR_Off = 28
cnIR_VIdeo1 = 31
cnIR_VIdeo2 = 32
cnIR_VIdeo3 = 33
cnIR_VIdeo4 = 34
cnIR_VIdeo5 = 35
cnIR_VIdeo6 = 36

(***********************************************************)
(*              DATA TYPE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_TYPE

(***********************************************************)
(*               VARIABLE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_VARIABLE

(***********************************************************)
(*               LATCHING DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_LATCHING

(***********************************************************)
(*       MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW           *)
(***********************************************************)
DEFINE_MUTUALLY_EXCLUSIVE

(***********************************************************)
(*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)

Define_Call 'PULSE_IR' (DEV dvDEV, INTEGER nCHAN)
{
  Send_Command dvDev,"'SP',nChan"
}

Define_Call 'TV_INPUT' (nInput)
{
	If ([vdvTV,cnTV_On])
	{
		Cancel_Wait 'TV_ON_WAIT'
		Call 'PULSE_IR' (dvTV, nInput)
	}
	Else
	{
		Cancel_Wait 'TV_ON_WAIT'
		Call 'PULSE_IR' (dvTV, cnIR_On)
		Off[vdvTV, cnTV_Off]
		On[vdvTV, cnTV_On]
		Wait 50 'TV_ON_WAIT'
		{
			Call 'PULSE_IR' (dvTV, nInput)
		}
	}
}

(***********************************************************)
(*                STARTUP CODE GOES BELOW                  *)
(***********************************************************)
DEFINE_START

(***********************************************************)
(*                THE EVENTS GO BELOW                      *)
(***********************************************************)
DEFINE_EVENT
Button_Event[vdvTV, cnTV_On]
{
	Push:
	{
		Cancel_Wait 'TV_ON_WAIT'
		Call 'PULSE_IR' (dvTV, cnIR_On)
		On[vdvTV, cnTV_On]
		Off[vdvTV, cnTV_Off]
	}
}

Button_Event[vdvTV, cnTV_Off]
{
	Push:
	{
		Cancel_Wait 'TV_ON_WAIT'
		Call 'PULSE_IR' (dvTV, cnIR_Off)
		On[vdvTV, cnTV_Off]
		Off[vdvTV, cnTV_On]
	}
}

Button_Event[vdvTV, cnTV_Input1]
{
	Push:
	{
		Call 'TV_INPUT' (cnIR_Video1)
	}
}

Button_Event[vdvTV, cnTV_Input2]
{
	Push:
	{
		Call 'TV_INPUT' (cnIR_Video2)
	}
}

Button_Event[vdvTV, cnTV_Input3]
{
	Push:
	{
		Call 'TV_INPUT' (cnIR_Video3)
	}
}

Button_Event[vdvTV, cnTV_Input4]
{
	Push:
	{
		Call 'TV_INPUT' (cnIR_Video4)
	}
}

Button_Event[vdvTV, cnTV_Input5]
{
	Push:
	{
		Call 'TV_INPUT' (cnIR_Video5)
	}
}

Button_Event[vdvTV, cnTV_Input6]
{
	Push:
	{
		Call 'TV_INPUT' (cnIR_Video6)
	}
}

(***********************************************************)
(*            THE ACTUAL PROGRAM GOES BELOW                *)
(***********************************************************)
DEFINE_PROGRAM

(***********************************************************)
(*                     END OF PROGRAM                      *)
(*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
(***********************************************************)
